package com.blue.mapper.workflow;

import com.blue.po.workflow.TaskInstancePO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.blue.vo.workflow.TaskInstanceVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 流程任务实例表
 *
 * @author nanjie.chen
 * @email 15696471158@163.com
 * @date 2025-03-07
 */
@Mapper
public interface TaskInstanceMapper extends BaseMapper<TaskInstancePO> {
    @Select("(SELECT t.operation_time,t.assignee_id,t.status,t.remark,t1.username as assignee,t.create_time as createTime\n" +
            "FROM workflow_task_instance t\n" +
            "LEFT JOIN author_user t1\n" +
            "ON t1.user_id = t.assignee_id\n" +
            "WHERE t.instance_id = #{instanceId})\n" +
            "UNION ALL\n" +
            "(SELECT t.start_time as operationTime, t.initiator_id as assigneeId ,'5' as status,'无' as remark,t1.username as assignee,t.start_time as createTime\n" +
            "FROM workflow_instance t\n" +
            "LEFT JOIN author_user t1\n" +
            "ON t1.user_id = t.initiator_id WHERE t.id = #{instanceId})\n" +
            "ORDER BY createTime desc")
    List<TaskInstanceVO> taskNodeList(@Param("instanceId") String instanceId);
}
